<template>
  <PageBox :data="dataInfo" :isSelect="isSelect" :isCheckbox="isCheckbox" @tableRadioBtn="tableRadioBtn"
    @tableCheckboxBtn="tableCheckboxBtn" @searchBtn="getTbody">
    <template #search="{ search }" v-if="!isSelect">
      <ElFormItemBox label="库位名称" prop="likeWords">
        <ElInputBox :data="search" dataName="likeWords" />
      </ElFormItemBox>
    </template>
    <template #item="{ row }">
      <div class="warehouseItem">
        <div class="warehouseItem-header" :class="{
          'bg-color-success': row.isEnabled === 1,
          'bg-color-info': row.isEnabled === 0,
        }">
          {{ `${row.areaCodeName}${row.isFinishedProductInventory === 1 ? `【成品库位】` : ''}` }}
        </div>
        <div class="warehouseItem-main">
          <h3>{{ `${row.areaShelfName}` }}</h3>
        </div>
        <div class="warehouseItem-operation list-r-8" v-if="dataInfo.table.operation?.length > 0">
          <template v-for="(item, itemIndex) in dataInfo.table.operation">
            <el-divider direction="vertical" v-if="itemIndex !== 0" />
            <el-link :icon="item.icon" @click="item.click(row, itemIndex)">{{ typeof item.title === 'function' ?
              item.title(row) :
              item.title }}</el-link>
          </template>
        </div>
      </div>
    </template>
  </PageBox>
  <ElPupFormBox :pup="pupAdd">
    <template #default="{ form }">
      <ElFormItemBox label="所属库区" prop="areaCode" isRules>
        <ElSelectBox :data="form" dataName="areaCode" :options="options.area" />
      </ElFormItemBox>
      <ElFormItemBox label="新增库位数" prop="areaShelfCount" isRules>
        <ElNumberBox :data="form" dataName="areaShelfCount" />
      </ElFormItemBox>
    </template>
  </ElPupFormBox>
  <ElPupFormBox :pup="pupWarehouseLocation">
    <template #default="{ form }">
      <ElFormItemBox label="库位名称" prop="areaShelfName" isRules>
        <ElInputBox :data="form" dataName="areaShelfName" />
      </ElFormItemBox>
      <ElFormItemBox label="成品库位" prop="isFinishedProductInventory">
        <ElSwitchBox :data="form" dataName="isFinishedProductInventory" />
      </ElFormItemBox>
    </template>
  </ElPupFormBox>
</template>
<script setup lang="ts">
const { proxy } = getCurrentInstance() as any;
import './pageCss.scss'; // 引入样式
const props = withDefaults(
  defineProps<{
    isSelect?: boolean;//是否是选择页面
    isCheckbox?: boolean;//是否多选
    search?: any;//筛选条件
    selectable?: Function;//筛选条件
  }>(),
  {

  },
);
//弹窗-数据
const pupWarehouseLocation: any = reactive({
  state: false,
  typeName: '3',
  title: `库区管理`,
  width: 600,
  height: 'auto',
  form: {
    warehouseCode: "",//仓库编码（唯一识别码
    areaCode: "",//仓库分区代码（唯一识别码）
    areaShelfCount: 0,//库位新增数量
    isFinishedProductInventory: 0,//是否成品库存
  },
  btns: [
    {
      title: '保存',
      type: 'primary',
      click: (pup: any) => {
        pup.loading = true
        proxy.$api.WarehouseAreaShelf.UpdateAreaShelf(pup.form)
          .then((res: any) => {
            pup.state = false
            proxy.$message(`保存成功`);
            getTbody()
          }).catch(() => {
            pup.loading = false
          })
      }
    }
  ]
});
//弹窗-数据
const pupAdd: any = reactive({
  state: false,
  typeName: 0,
  title: `库位管理`,
  width: 600,
  height: 'auto',
  form: {
    warehouseCode: "",//仓库编码（唯一识别码
    areaCode: "",//仓库分区代码（唯一识别码）
    areaShelfCount: 0,//库位新增数量
    isFinishedProductInventory: 0,//是否成品库存
  },
  btns: [
    {
      title: '保存',
      type: 'primary',
      click: (pup: any) => {
        pup.loading = true
        proxy.$api.OrderBusniess.UpdateCustomerContract({
          ...pup.form,
          warehouseCode: dataInfo.warehouseCode,
        })
          .then((res: any) => {
            pup.state = false
            proxy.$message(`保存成功`);
            getTbody()
          }).catch(() => {
            pup.loading = false
          })
      }
    }
  ]
});
import { useListComponent } from './pageTs'; // 引入逻辑
const { dataInfo, getTbody, getWarehouse, getTabs, options } = useListComponent({
  ...props,
  pupAdd: pupAdd,
  pupWarehouseLocation: pupWarehouseLocation,
});
const emit = defineEmits<{
  //fn为父组件引入子组件是定义的子组件事件属性，可随意定义
  (event: 'tableRadioBtn', row: any): void;
  (event: 'tableCheckboxBtn', arr: any): void;
}>();
//多选数据
const tableCheckboxBtn = (arr: any) => {
  emit('tableCheckboxBtn', arr);
};
//单选数据
const tableRadioBtn = (row: any) => {
  emit('tableRadioBtn', row);
};
onMounted(() => {
  getWarehouse()
});
</script>